﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;
using QualityRpt.Service;
using log4net;
using System.Collections;
using QualityRpt.Utils;

namespace QualityRPT
{
    public partial class AirWireUnread : System.Web.UI.Page
    {
        static ILog logger = LogManager.GetLogger("AirWireUnread");
        int Suppliername = DeviceService.AIRWIRE_DEV;//标识 3 为天线厂商
        public string PagerHtml = string.Empty;
        public string PagerHtml2 = string.Empty;
        public string strpage = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                this.h_dev.Value = Suppliername.ToString();
                DataTable sptable = DeviceSupplierService.GetListSupplierName(string.Empty, string.Empty, Suppliername);
                this.ajax_spin.DataSource = sptable;
                this.ajax_spin.DataTextField = "SUPPLIER_NAME"; this.ajax_spin.DataValueField = "ID";
                this.ajax_spin.DataBind();

				DataTable initscTable =  DeviceSpecService.GetBySpIn(string.Empty, Suppliername);
				this.ajax_scin.DataSource = initscTable;
				this.ajax_scin.DataTextField = "SPEC_NAME"; this.ajax_scin.DataValueField = "ID";
				this.ajax_scin.DataBind ();

                DataTable rdtable = NetWorkPlazaService.GetRoadList();//获得所有路段
                this.ajax_rdin.DataSource = rdtable;
                this.ajax_rdin.DataTextField = "ORGAN_NAME"; this.ajax_rdin.DataValueField = "ORGAN_ID";
                this.ajax_rdin.DataBind();

				DataTable plTable = NetWorkPlazaService.GetListByRdIn(string.Empty);//默认获得所有广场
				this.ajax_plazain.DataSource = plTable;
				this.ajax_plazain.DataTextField = "ORGAN_NAME"; this.ajax_plazain.DataValueField = "ORGAN_ID";
				this.ajax_plazain.DataBind ();

                DataTable lanetable = AirwirePlazaService.GetAllLane();//获得所有车道
                this.ajax_lanein.DataSource = lanetable;
                this.ajax_lanein.DataTextField = "LANE_NO"; this.ajax_lanein.DataValueField = "LANE_NO";
                this.ajax_lanein.DataBind();
                GetParams();
                if (strpage != string.Empty)
                {
                    BindData();
                }
                else
                {
                    this.textBoxStart.Text = DateTime.Now.ToString("yyyy-MM-dd 00:00");
                    this.textBoxEnd.Text = DateTime.Now.ToString("yyyy-MM-dd 23:59");
                }
            }
        }
        DateTime startTime; DateTime endTime; string strSpIn;
        string strSpecIn; string strRdIn; string strPlazaIn;
        string strLaneIn; int istatType = 0; string strStatType;
        string strStartTime; string strEndTime;
        /// <summary>
        /// 从url中获取
        /// </summary>
        private void GetParams()
        {
            strpage = Request.Params["p"];
            if (strpage == null)
            {
                strpage = string.Empty;
            }
            strSpIn = Request.Params["spin"];
            strSpecIn = Request.Params["scin"];
            strRdIn = Request.Params["rdin"];
            strPlazaIn = Request.Params["plin"];
            strLaneIn = Request.Params["lnin"];
            strStartTime = Request.Params["t1"];
            strEndTime = Request.Params["t2"];
            strStatType = Request.Params["tt"];
        }
        /// <summary>
        /// 从form中获取
        /// </summary>
        private void PostParams()
        {
            strpage = string.Empty;
            strSpIn = Request.Params["ajax_spin"];
            strSpecIn = Request.Params["ajax_scin"];
            strRdIn = Request.Params["ajax_rdin"];
            strPlazaIn = Request.Params["ajax_plazain"];
            strLaneIn = Request.Params["ajax_lanein"];
            strStartTime = Request.Params["textBoxStart"];
            strEndTime = Request.Params["textBoxEnd"];
            strStatType = Request.Params["sel_statTType"];
        }
        private void BindParams()
        {
            if (strpage == string.Empty)
            {
                strpage = "1";
            }
            #region 设置选中状态
            //厂商选中状态
            if (strSpIn != null && strSpIn.Trim() != string.Empty)
            {
                string[] selSpin = strSpIn.Split(new char[] { ',' });
                Hashtable hashSelSp = new Hashtable();
                for (int i = 0; i < selSpin.Length; i++)
                {
                    hashSelSp.Add(selSpin[i], 0);
                }
                for (int i = 0; i < ajax_spin.Items.Count; i++)
                {
                    if (hashSelSp.ContainsKey(ajax_spin.Items[i].Value))
                    {
                        ajax_spin.Items[i].Selected = true;
                    }
                }
            }
            //路段选中状态
            if (strRdIn != null && strRdIn.Trim() != string.Empty)
            {
                string[] selRdin = strRdIn.Split(new char[] { ',' });
                Hashtable hashSelRd = new Hashtable();
                for (int i = 0; i < selRdin.Length; i++)
                {
                    hashSelRd.Add(selRdin[i], 0);
                }
                for (int i = 0; i < ajax_rdin.Items.Count; i++)
                {
                    if (hashSelRd.ContainsKey(ajax_rdin.Items[i].Value))
                    {
                        ajax_rdin.Items[i].Selected = true;
                    }
                }
            }
            //车道状态
            if (strLaneIn != null && strLaneIn.Trim() != string.Empty)
            {
                string[] selLanein = strLaneIn.Split(new char[] { ',' });
                Hashtable hashSelLane = new Hashtable();
                for (int i = 0; i < selLanein.Length; i++)
                {
                    hashSelLane.Add(selLanein[i], 0);
                }
                for (int i = 0; i < ajax_lanein.Items.Count; i++)
                {
                    if (hashSelLane.ContainsKey(ajax_lanein.Items[i].Value))
                    {
                        ajax_lanein.Items[i].Selected = true;
                    }
                }
            }
            //型号选中状态
            if (strSpIn == null)
            {
                strSpIn = string.Empty;
            }
            DataTable sctable = DeviceSpecService.GetBySpIn(strSpIn, Suppliername);
            this.ajax_scin.DataSource = sctable;
            this.ajax_scin.DataTextField = "SPEC_NAME"; this.ajax_scin.DataValueField = "ID";
            this.ajax_scin.DataBind();
            if (strSpecIn != null && strSpecIn.Trim() != string.Empty)
            {
                string[] selScin = strSpecIn.Split(new char[] { ',' });
                Hashtable hashSelSc = new Hashtable();
                for (int i = 0; i < selScin.Length; i++)
                {
                    hashSelSc.Add(selScin[i], 0);
                }
                for (int i = 0; i < ajax_scin.Items.Count; i++)
                {
                    if (hashSelSc.ContainsKey(ajax_scin.Items[i].Value))
                    {
                        ajax_scin.Items[i].Selected = true;
                    }
                }
            }
            //广场选中状态
            if (strRdIn == string.Empty)
            {
                strRdIn = string.Empty;
            }
            DataTable plazatable = NetWorkPlazaService.GetListByRdIn(strRdIn);
            this.ajax_plazain.DataSource = plazatable;
            this.ajax_plazain.DataTextField = "ORGAN_NAME"; this.ajax_plazain.DataValueField = "ORGAN_ID";
            this.ajax_plazain.DataBind();
            if (strPlazaIn != null && strPlazaIn.Trim() != string.Empty)
            {
                string[] selPlazain = strPlazaIn.Split(new char[] { ',' });
                Hashtable hashSelPlaza = new Hashtable();
                for (int i = 0; i < selPlazain.Length; i++)
                {
                    if (!hashSelPlaza.ContainsKey(selPlazain[i]))
                    {
                        hashSelPlaza.Add(selPlazain[i], 0);
                    }
                }
                for (int i = 0; i < ajax_plazain.Items.Count; i++)
                {
                    if (hashSelPlaza.ContainsKey(ajax_plazain.Items[i].Value))
                    {
                        ajax_plazain.Items[i].Selected = true;
                    }
                }
            }
            #endregion
            if (strStartTime != null && strStartTime != string.Empty)
            {
                textBoxStart.Text = strStartTime;
                startTime = DateTime.Parse(strStartTime);
            }
            if (strEndTime != null && strEndTime != string.Empty)
            {
                textBoxEnd.Text = strEndTime;
                endTime = DateTime.Parse(strEndTime).AddSeconds(59);
            }
            if (strStatType != null && strStatType.Trim() != string.Empty)
            {
                istatType = Convert.ToInt32(strStatType);
                sel_statTType.Value = strStatType;
            }
        }
        private void BindData()
        {
            BindParams();
            DateTime trackStart = DateTime.Now;
            StringBuilder sbGroupTitle = new StringBuilder();
            StringBuilder sbGroupNameTitle = new StringBuilder();
            bool nogroup = true;
            if (strRdIn != null && strRdIn.Trim() != string.Empty)
            {
                sbGroupTitle.Append("路段,");nogroup = false;
                sbGroupNameTitle.Append("ROAD_NAME,");
            }
            if (strSpIn != null && strSpIn.Trim() != string.Empty)
            {
                sbGroupTitle.Append("厂商,"); nogroup = false;
                sbGroupNameTitle.Append("SUPPLIER_NAME,");
            }
            if (strSpecIn != null && strSpecIn.Trim() != string.Empty)
            {
                sbGroupTitle.Append("型号,"); nogroup = false;
                sbGroupNameTitle.Append("SPEC_NAME,");
            }
            switch (istatType)
            {
                case 1:
                    sbGroupTitle.Append("年,月,"); sbGroupNameTitle.Append("STYEAR,STMONTH,");
                    break;
                case 2:
                    sbGroupTitle.Append("年,周,"); sbGroupNameTitle.Append("STYEAR,STWEEK,");
                    break;
                case 3:
                    sbGroupTitle.Append("年,月,日,"); sbGroupNameTitle.Append("STYEAR,STMONTH,STDAY,");
                    break;
                case 4:
                    sbGroupTitle.Append("年,月,日,时,"); sbGroupNameTitle.Append("STYEAR,STMONTH,STDAY,STHOUR,");
                    break;
            }
            if (nogroup)
            {
                sbGroupTitle.Append("路段,厂商,型号,");
                sbGroupNameTitle.Append("ROAD_NAME,SUPPLIER_NAME,SPEC_NAME,");
            }
            AutoColumns = sbGroupNameTitle.ToString().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            AutoColumnTitles = sbGroupTitle.ToString().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            this.repeater_title.DataSource = AutoColumnTitles; this.repeater_title.DataBind();
            string statIndic = "TRANSCOUNT,UNREAD_TRANSCOUNT,UNREAD_RATE";
            statTable = TransNoteService.GetAIRStatByQ(startTime, endTime, statIndic, istatType, strSpIn, strSpecIn, strRdIn, strPlazaIn, strLaneIn, true);
            this.repeater_data.DataSource = statTable; this.repeater_data.DataBind();
            //获得明细
            PageUtils pu = new PageUtils(); pu.PerPageNum = 50; pu.Page = Convert.ToInt32(strpage);
            detailTable = UNReadTransService.GetAIRDetailByQ(startTime, endTime, strSpIn, strSpecIn, strRdIn, strPlazaIn, strLaneIn, pu);
            this.repeater_Detail.DataSource = detailTable; this.repeater_Detail.DataBind();
            string pagerparam = "/AirWireUnread.aspx?pid=" + Request.Params["pid"] + "&cid=" + Request.Params["cid"] + "&p={page}&t1=" + strStartTime + "&t2=" + strEndTime
               + "&spin=" + strSpIn + "&scin=" + strSpecIn + "&rdin=" + strRdIn + "&plin=" + strPlazaIn + "&lnin=" + strLaneIn + "&tt=" + strStatType;
            PagerHtml = pu.GenStPagination(pagerparam+"&tab=tabDetail");
            //获得天线明细
            airWireTable = UNReadTransService.GetAIRGDetailByQ(startTime, endTime, strSpIn, strSpecIn, strRdIn, strPlazaIn, strLaneIn, pu);
            this.repeater_airdata.DataSource = airWireTable; this.repeater_airdata.DataBind();
            PagerHtml2 = pu.GenStPagination(pagerparam + "&tab=tabAIR");
            TimeSpan tsCounsume = DateTime.Now - trackStart;
            this.span_t_consume.InnerText = "耗时:" + tsCounsume.TotalSeconds + "s";
        }
        protected void ButtonQ_Click(object sender, EventArgs e)
        {
            PostParams();
            BindData();
        }
        DataTable statTable = null;
        DataTable detailTable = null;
        DataTable airWireTable = null;
        DataTable airWireTableNoPage = null;

        string[] AutoColumns = null;
        string[] AutoColumnTitles = null;
        /// <summary>
        /// 根据列名生成需要显示的分组列
        /// </summary>
        /// <param name="rIndex"></param>
        /// <returns></returns>
        public string GetAutoColumns(object rIndex)
        {
            StringBuilder sbText = new StringBuilder();
            if (AutoColumns != null && statTable != null)
            {
                for (int i = 0; i < AutoColumns.Length; i++)
                {
                    sbText.Append("<td>" + statTable.Rows[Convert.ToInt32(rIndex)][AutoColumns[i]] + "</td>");
                }
            }
            return sbText.ToString();
        }
        //导出天线漏读统计
        protected void ButtonExport_Click(object sender, EventArgs e)
        {
            if (statTable == null)
            {
                PostParams();
                BindData();
                
                string checkDate = DateTime.Parse(textBoxStart.Text).ToString("yyyy年MM月dd日") + "-" + DateTime.Parse(textBoxEnd.Text).ToString("yyyy年MM月dd日");
                string reportFile = Server.MapPath("/ReportTemplate/天线漏读统计报表.xls");
                SpreadsheetGear.IWorkbook workbook = SpreadsheetGear.Factory.GetWorkbook(reportFile);
                if (statTable == null || statTable.Rows.Count == 0)
                {
                    Common.Utility.Alert("您查询的内容不存在！", this.Page);
                    return;
                }
                //设置虚拟数据表newtab存放所要的数据列
                DataTable newtab = new DataTable();
                //判断分组情况
                switch (istatType)
                {
                    case 1:
                        newtab.Columns.Add("年份");
                        newtab.Columns.Add("月份");
                        break;
                    case 2:
                        newtab.Columns.Add("年份");
                        newtab.Columns.Add("周");
                        break;
                    case 3:
                        newtab.Columns.Add("年份");
                        newtab.Columns.Add("月份");
                        newtab.Columns.Add("日");
                        break;
                    case 4:
                        newtab.Columns.Add("年份");
                        newtab.Columns.Add("月份");
                        newtab.Columns.Add("日");
                        newtab.Columns.Add("时");
                        break;
                }
                if (strRdIn != null && strRdIn.Trim() != string.Empty)
                {
                    newtab.Columns.Add("路段");
                }
                if (strSpIn != null && strSpIn.Trim() != string.Empty)
                {
                    newtab.Columns.Add("厂商");
                }
                if (strSpecIn != null && strSpecIn.Trim() != string.Empty)
                {
                    newtab.Columns.Add("型号");
                }
                if ((strSpIn == null || strSpIn.Trim() == string.Empty) && (strSpecIn == null || strSpecIn.Trim() == string.Empty) && (strRdIn == null || strRdIn.Trim() == string.Empty))
                {
                    newtab.Columns.Add("路段");
                    newtab.Columns.Add("厂商");
                    newtab.Columns.Add("型号");
                }
                newtab.Columns.Add("总交易量");
                newtab.Columns.Add("漏读量");
                newtab.Columns.Add("漏读率");

                //遍历源数据表对新数据表各行进行赋值
                for (int i = 0; i < statTable.Rows.Count; i++)
                {
                    DataRow newRow = newtab.NewRow();
                    switch (istatType)
                    {
                        case 1:
                            newRow["年份"] = statTable.Rows[i]["STYEAR"];
                            newRow["月份"] = statTable.Rows[i]["STMONTH"];
                            break;
                        case 2:
                            newRow["年份"] = statTable.Rows[i]["STYEAR"];
                            newRow["周"] = statTable.Rows[i]["STWEEK"];
                            break;
                        case 3:
                            newRow["年份"] = statTable.Rows[i]["STYEAR"];
                            newRow["月份"] = statTable.Rows[i]["STMONTH"];
                            newRow["日"] = statTable.Rows[i]["STDAY"];
                            break;
                        case 4:
                            newRow["年份"] = statTable.Rows[i]["STYEAR"];
                            newRow["月份"] = statTable.Rows[i]["STMONTH"];
                            newRow["日"] = statTable.Rows[i]["STDAY"];
                            newRow["时"] = statTable.Rows[i]["STHOUR"];
                            break;
                    }
                    if (strRdIn != null && strRdIn.Trim() != string.Empty)
                    {
                        newRow["路段"] = statTable.Rows[i]["ROAD_NAME"];
                    }
                    if (strSpIn != null && strSpIn.Trim() != string.Empty)
                    {
                        newRow["厂商"] = statTable.Rows[i]["SUPPLIER_NAME"];
                    }
                    if (strSpecIn != null && strSpecIn.Trim() != string.Empty)
                    {
                        newRow["型号"] = statTable.Rows[i]["SPEC_NAME"];
                    }
                    if ((strSpIn == null || strSpIn.Trim() == string.Empty) && (strSpecIn == null || strSpecIn.Trim() == string.Empty) && (strRdIn == null || strRdIn.Trim() == string.Empty))
                    {
                        newRow["路段"] = statTable.Rows[i]["ROAD_NAME"];
                        newRow["厂商"] = statTable.Rows[i]["SUPPLIER_NAME"];
                        newRow["型号"] = statTable.Rows[i]["SPEC_NAME"];
                    }
                    newRow["总交易量"] = statTable.Rows[i]["TRANSCOUNT"];
                    newRow["漏读量"] = statTable.Rows[i]["UNREAD_TRANSCOUNT"];
                    newRow["漏读率"] = statTable.Rows[i]["UNREAD_RATE"];
                    newtab.Rows.Add(newRow);
                }
                #region 拼表格名称
                string b = ""; string c = ""; string d = ""; string f = "";
                switch (istatType)
                {
                    case 0://无分组                        
                        b = "无分组";
                        break;
                    case 1://按月                      
                        b = "按月";
                        break;
                    case 2://按周                        
                        b = "按周";
                        break;
                    case 3://按日                        
                        b = "按日";
                        break;
                    case 4://按时                       
                        b = "按时";
                        break;
                }
                if (strSpIn != null && strSpIn.Trim() != string.Empty)
                {
                    c = "厂商";
                }
                if (strSpecIn != null && strSpecIn.Trim() != string.Empty)
                {
                    d = "型号";
                }
                if (strRdIn != null && strRdIn.Trim() != string.Empty)
                {
                    f = "路段";
                }
                #endregion
                string file_name = "天线漏读统计" + b + c + d + f + "报表" + "(" + DateTime.Parse(textBoxStart.Text).ToString("yyyy-MM-dd_HH：mm：ss") + "-" + DateTime.Parse(textBoxEnd.Text).ToString("yyyy-MM-dd_HH：mm：ss") + ")" + ".xls";
                switch (istatType)
                {
                    case 0://无分组
                        {
                            #region 厂商、型号、路段排列组合的八种
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn != null && (strRdIn != null && strRdIn.Trim() != string.Empty))//厂商、型号、路段都不为空
                            {
                                string[] aa = new string[] { "G" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn != null && (strRdIn == null || strRdIn.Trim() == string.Empty))//厂商不为空、型号不为空、路段为空
                            {
                                string[] aa = new string[] { "F"};
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);

                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn == null && (strRdIn != null && strRdIn.Trim() != string.Empty))//厂商不为空、型号为空、路段不为空
                            {
                                string[] aa = new string[] { "F"};
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn == null && (strRdIn == null || strRdIn.Trim() == string.Empty))//厂商不为空、型号为空、路段为空
                            {
                                string[] aa = new string[] { "E"};
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn == null && (strRdIn == null || strRdIn.Trim() == string.Empty))//厂商为空、型号为空、路段为空
                            {
                                string[] aa = new string[] { "G" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn == null && (strRdIn != null && strRdIn.Trim() != string.Empty))//厂商为空、型号为空、路段不为空
                            {
                                string[] aa = new string[] { "E" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn != null && (strRdIn == null || strRdIn.Trim() == string.Empty))//厂商为空、型号不为空、路段为空
                            {
                                string[] aa = new string[] { "E" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn != null && (strRdIn != null && strRdIn.Trim() != string.Empty))//厂商为空、型号不为空、路段不为空
                            {
                                string[] aa = new string[] { "F" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            break;
                            #endregion
                        }
                    case 1://按月
                        {
                            #region  厂商、型号、路段排列组合的八种
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn != null && (strRdIn != null && strRdIn.Trim() != string.Empty))//厂商、型号、路段都不为空
                            {
                                string[] aa = new string[] { "I" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn != null && (strRdIn == null || strRdIn.Trim() == string.Empty))//厂商不为空、型号不为空、路段为空
                            {
                                string[] aa = new string[] { "H" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);

                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn == null && (strRdIn != null && strRdIn.Trim() != string.Empty))//厂商不为空、型号为空、路段不为空
                            {
                                string[] aa = new string[] { "H"};
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn == null && (strRdIn == null || strRdIn.Trim() == string.Empty))//厂商不为空、型号为空、路段为空
                            {
                                string[] aa = new string[] { "G"};
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn == null && (strRdIn == null || strRdIn.Trim() == string.Empty))//厂商为空、型号为空、路段为空
                            {
                                string[] aa = new string[] { "I"};
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn == null && (strRdIn != null && strRdIn.Trim() != string.Empty))//厂商为空、型号为空、路段不为空
                            {
                                string[] aa = new string[] { "G" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn != null && (strRdIn == null || strRdIn.Trim() == string.Empty))//厂商为空、型号不为空、路段为空
                            {
                                string[] aa = new string[] { "G" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn != null && (strRdIn != null && strRdIn.Trim() != string.Empty))//厂商为空、型号不为空、路段不为空
                            {
                                string[] aa = new string[] { "H"};
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            break;
                            #endregion
                        }
                    case 2://按周
                        {
                            #region  厂商、型号、路段排列组合的八种
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn != null && (strRdIn != null && strRdIn.Trim() != string.Empty))//厂商、型号、路段都不为空
                            {
                                string[] aa = new string[] { "I" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn != null && (strRdIn == null || strRdIn.Trim() == string.Empty))//厂商不为空、型号不为空、路段为空
                            {
                                string[] aa = new string[] { "H" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);

                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn == null && (strRdIn != null && strRdIn.Trim() != string.Empty))//厂商不为空、型号为空、路段不为空
                            {
                                string[] aa = new string[] { "H" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn == null && (strRdIn == null || strRdIn.Trim() == string.Empty))//厂商不为空、型号为空、路段为空
                            {
                                string[] aa = new string[] { "G" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn == null && (strRdIn == null || strRdIn.Trim() == string.Empty))//厂商为空、型号为空、路段为空
                            {
                                string[] aa = new string[] { "I" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn == null && (strRdIn != null && strRdIn.Trim() != string.Empty))//厂商为空、型号为空、路段不为空
                            {
                                string[] aa = new string[] { "G" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn != null && (strRdIn == null || strRdIn.Trim() == string.Empty))//厂商为空、型号不为空、路段为空
                            {
                                string[] aa = new string[] { "G" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn != null && (strRdIn != null && strRdIn.Trim() != string.Empty))//厂商为空、型号不为空、路段不为空
                            {
                                string[] aa = new string[] { "H" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            break;
                            #endregion
                        }
                    case 3://按日
                        {
                            #region  厂商、型号、路段排列组合的八种
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn != null && (strRdIn != null && strRdIn.Trim() != string.Empty))//厂商、型号、路段都不为空
                            {
                                string[] aa = new string[] { "J"};
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn != null && (strRdIn == null || strRdIn.Trim() == string.Empty))//厂商不为空、型号不为空、路段为空
                            {
                                string[] aa = new string[] { "I"};
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);

                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn == null && (strRdIn != null && strRdIn.Trim() != string.Empty))//厂商不为空、型号为空、路段不为空
                            {
                                string[] aa = new string[] { "I"};
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn == null && (strRdIn == null || strRdIn.Trim() == string.Empty))//厂商不为空、型号为空、路段为空
                            {
                                string[] aa = new string[] { "H" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn == null && (strRdIn == null || strRdIn.Trim() == string.Empty))//厂商为空、型号为空、路段为空
                            {
                                string[] aa = new string[] { "J" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn == null && (strRdIn != null && strRdIn.Trim() != string.Empty))//厂商为空、型号为空、路段不为空
                            {
                                string[] aa = new string[] { "H" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn != null && (strRdIn == null || strRdIn.Trim() == string.Empty))//厂商为空、型号不为空、路段为空
                            {
                                string[] aa = new string[] { "H" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn != null && (strRdIn != null && strRdIn.Trim() != string.Empty))//厂商为空、型号不为空、路段不为空
                            {
                                string[] aa = new string[] { "I" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            break;
                            #endregion
                        }
                    case 4://按时
                        {
                            #region  厂商、型号、路段排列组合的八种
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn != null && (strRdIn != null && strRdIn.Trim() != string.Empty))//厂商、型号、路段都不为空
                            {
                                string[] aa = new string[] { "K" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn != null && (strRdIn == null || strRdIn.Trim() == string.Empty))//厂商不为空、型号不为空、路段为空
                            {
                                string[] aa = new string[] { "J"};
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);

                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn == null && (strRdIn != null && strRdIn.Trim() != string.Empty))//厂商不为空、型号为空、路段不为空
                            {
                                string[] aa = new string[] { "J" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn == null && (strRdIn == null || strRdIn.Trim() == string.Empty))//厂商不为空、型号为空、路段为空
                            {
                                string[] aa = new string[] { "I" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn == null && (strRdIn == null || strRdIn.Trim() == string.Empty))//厂商为空、型号为空、路段为空
                            {
                                string[] aa = new string[] { "K" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn == null && (strRdIn != null && strRdIn.Trim() != string.Empty))//厂商为空、型号为空、路段不为空
                            {
                                string[] aa = new string[] { "I" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn != null && (strRdIn == null || strRdIn.Trim() == string.Empty))//厂商为空、型号不为空、路段为空
                            {
                                string[] aa = new string[] { "I" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn != null && (strRdIn != null && strRdIn.Trim() != string.Empty))//厂商为空、型号不为空、路段不为空
                            {
                                string[] aa = new string[] { "J" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            break;
                            #endregion
                        }
                }
            }
        }
        //导出天线漏读信息
        protected void ButtonExportDetail_Click(object sender, EventArgs e)
        {
            if (airWireTableNoPage == null)
            {
                PostParams();
                BindData();
                //获得全部天线明细（无分页）
                airWireTableNoPage = UNReadTransService.GetAIRGDetailByQ(startTime, endTime, strSpIn, strSpecIn, strRdIn, strPlazaIn, strLaneIn, null);
                if (airWireTableNoPage == null || airWireTableNoPage.Rows.Count == 0)
                {
                    Common.Utility.Alert("您查询的内容不存在！", this.Page);
                    return;
                }
                DataTable newtab = new DataTable();
                newtab.Columns.Add("厂商名称");
                newtab.Columns.Add("天线型号");
                newtab.Columns.Add("广场");
                newtab.Columns.Add("车道");
                newtab.Columns.Add("漏读交易次数");
                newtab.Columns.Add("总交易次数");
                newtab.Columns.Add("漏读率");
                for (int i = 0; i < airWireTableNoPage.Rows.Count; i++)
                {

                    DataRow newRow = newtab.NewRow();
                    newRow["厂商名称"] = airWireTableNoPage.Rows[i]["AIRWIRE_SUPPLIER_NAME"];
                    newRow["天线型号"] = airWireTableNoPage.Rows[i]["AIRWIRE_SPEC_NAME"];
                    newRow["广场"] = airWireTableNoPage.Rows[i]["PLAZA_NAME"];
                    newRow["车道"] = airWireTableNoPage.Rows[i]["LANENO"];
                    newRow["漏读交易次数"] = airWireTableNoPage.Rows[i]["UNREAD_TRANSCOUNT"];
                    newRow["总交易次数"] = airWireTableNoPage.Rows[i]["SUM_TRANSCOUNT"];
                    newRow["漏读率"] = airWireTableNoPage.Rows[i]["UNREAD_RATE"];
                    newtab.Rows.Add(newRow);
                }               
                string[] aa = new string[] { "H" };
                string file_name = "天线漏读信息统计报表" + "(" + DateTime.Parse(textBoxStart.Text).ToString("yyyy-MM-dd_HH：mm：ss") + "-" + DateTime.Parse(textBoxEnd.Text).ToString("yyyy-MM-dd_HH：mm：ss") + ")" + ".xls";
                string checkDate = DateTime.Parse(textBoxStart.Text).ToString("yyyy年MM月dd日") + "-" + DateTime.Parse(textBoxEnd.Text).ToString("yyyy年MM月dd日");
                string reportFile = Server.MapPath("/ReportTemplate/天线漏读信息统计报表.xls");
                SpreadsheetGear.IWorkbook workbook = SpreadsheetGear.Factory.GetWorkbook(reportFile);
                Common.Common.NOAutoExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);

            } 
        }
    }
}